/**
 * 
 */
package com.xintoucloud.gsv.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xintoucloud.gsv.entity.Role;
import com.xintoucloud.gsv.mapper.RoleMapper;
import com.xintoucloud.gsv.model.DataGrid;
import com.xintoucloud.gsv.model.RoleVo;
import com.xintoucloud.gsv.service.RoleService;

/**
 * @author xiang
 *
 */
@Service@Transactional
public class RoleServiceImpl implements RoleService{
	
	@Autowired
	private RoleMapper roleMapper;
	
	@Override	
	public List<Role> list() {
		return roleMapper.list();
	}

	@Override
	public List<RoleVo> showView() {
		List<RoleVo> roleVos = roleMapper.listRoleVo();
		return roleVos;
	}

	@Override
	public boolean roleDelete(int rid) {
		return roleMapper.roleDelete(rid)>0;
	}

	@Override
	public void roleAdd(Role role) {
		roleMapper.roleAdd(role);
	}

	@Override
	public boolean roleUpdate(Role role) {
		return roleMapper.roleUpdate(role)>0;
	}

	@Override
	public DataGrid<RoleVo> listByPageAndLimit(int page, int limit) {
		//System.out.println(page+"||"+limit);
		long pageIndex = (long)((page-1)*limit);  //该页第一个数据序号
		long count = roleMapper.count();
		//System.out.println(pageIndex+"||"+limit+"||"+count);
		List<RoleVo> roleVos = roleMapper.listByPageAndLimit(pageIndex, limit);
		//System.out.println("这是角色管理一页的数据条数"+roleVos.size());
		DataGrid<RoleVo> dataGrid = new DataGrid<>();
		if(roleVos != null) {
			dataGrid.setCount(count);
			dataGrid.setData(roleVos);
			dataGrid.setCode(0); // 默认端口状态(code值)为0
			dataGrid.setMsg("分页成功");
		}
		return dataGrid;
	}

}
